﻿<%@ page contentType="text/html;charset=utf-8" %>
<%@ page import="java.util.*" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DSDOWN 3DS DS DSI GB GBA WII WIIU Nintendo 任天堂 游戏 资讯 攻略 发售 下载</title>
<meta name="description" content="" />
<meta name="keywords" content="DSDOWN 3DS DS DSI GB GBA WII WIIU Nintendo 任天堂 游戏 攻略 发售 资讯 " />
<link href="style/index.css" rel="stylesheet" type="text/css" />
<style type="text/css">
</style></head>

<script src="script/jQuery.js" type="text/javascript"></script>
<script src="script/functions.js" type="text/javascript"></script>

<script language="javascript">
	var retail_year = 0;
	var retail_month = 0;
	var retail_games;
	
	$(document).ready(
	function()
	{
		retail_year = getNowYear();
		retail_month = getNowMonth();
		switchRetail();
	});
	
	function switchRetail()
	{
		$("#retail_date").text(retail_year+"年"+retail_month+"月");
		$("#retail_sheet").css("display","none");
		$("#retail_wait").css("display","block");
		$("#retail_error").css("display","none");
		// 开始请求数据
		$.ajax({
			type:"GET",
			url:"/interface/game_retail.do?pm=getGameRetailList&year=" + retail_year + "&month=" + retail_month,
			dateType:"json",
			cache:false,
			success:
				function(result)
				{
					var json = $.parseJSON(result);
					if (json.success=="true")
					{
						// 计算开始和结束日期
						var now = new Date();
						var source = "";
						var startdate = new Date(retail_year,retail_month-1,1);
						startdate.setDate(startdate.getDate()-startdate.getDay());
						var enddate = new Date(retail_year,retail_month-1,1);
						enddate.setMonth(enddate.getMonth()+1);
						enddate.setDate(enddate.getDate()-1+(7-enddate.getDay()));
		
						// 开始绘制日历
						retail_games = new Array();
						for(var i=0;i<42;i++)
						{
							var currdate = new Date(startdate.getYear(),startdate.getMonth(),startdate.getDate()+i);
							if (i%7==0) source+="<ul>";
							if (currdate.getMonth()+1==retail_month)
							{
								// 得出当天游戏/数量
								var games = new Array();
								for(var j=0;j<json.retail.length;j++)
								{
									// 先得出当天游戏总数
									if (json.retail[j].date==currdate.getDate())
									{
										var game = new Object();
										game.name = json.retail[j].name;
										game.id = json.retail[j].id;
										game.date = currdate.getDate();
										games[games.length] = game;
										retail_games[retail_games.length] = game;
									}
								}
								
								
								if (games.length>1)
								{
									source += "<li class='inlineli retail_body' onmouseover='showRetailDetail(this,"+currdate.getDate()+")'>";
									source += "<big>" + currdate.getDate() + "</big>"
									source+="<small>共"+games.length+"款游戏</small>";
								}
								else if (games.length==1)
								{
									source += "<li class='inlineli retail_body'>";
									source += "<big>" + currdate.getDate() + "</big>"
									source+="<small>"+games[0].name+"</small>";
								}
								else
								{
									source += "<li class='inlineli retail_body'>";
									source += "<big>" + currdate.getDate() + "</big>"
								}
								
								source += "</li>";
							}
							else
							{
								source += "<li class='inlineli retail_body_disabled'>";
								source += "<big>" + currdate.getDate() + "</big>"
								source += "</li>";				
							}
							if (i%7==6) source+="</ul>";
						}
						
						$("#retail_sheet").html(source);
						$("#retail_sheet").css("display","block");
						$("#retail_wait").css("display","none");
					}
					else
					{
						$("#retail_error").css("display","block");
						$("#retail_wait").css("display","none");
					}
				},
			error:
				function()
				{
					$("#retail_error").css("display","block");
					$("#retail_wait").css("display","none");
				}
		});
	}
	
	function showRetailDetail(box,date)
	{
		$("#retail_detail").css("display","block");
		$("#retail_detail").css("left",(box.offsetLeft-3)+"px");
		$("#retail_detail").css("top",(box.offsetTop-10)+"px");		
		$("#retail_detail_date").text(date);
		var source = "";
		for(var i=0;i<retail_games.length;i++)
		{
			if (retail_games[i].date == date)
			{
				source+="<a href='game_detail.do?id="+retail_games[i].id+"' retailchild='true'>"+retail_games[i].name+"</a>"
			}
		}
		$("#retail_detail_games").html(source);
	}
	
	function hideRetailDetail(obj,e)
	{
		e=e||window.event; 
		var obj=e.relatedTarget||e.toElement;
		if (obj.getAttribute("retailchild")!="true")
		{
			$('#retail_detail').css('display','none')
		}
	}
	
	function prevMonthRetail()
	{
		if (retail_month>1)
		{
			retail_month--;
		}
		else
		{
			retail_year--;
			retail_month = 12;
		}
		switchRetail();
	}
	
	function nextMonthRetail()
	{
		if (retail_month<12)
		{
			retail_month++;
		}
		else
		{
			retail_year++;
			retail_month = 1;
		}
		switchRetail();
	}
</script>

<body>

<div class="index">

<!-- 主页面 -->
<div class="main">

	<%@ include file="header.jsp" %>
	
	<%@ include file="stage.jsp" %>	
	
	<div class="header_shadow" style="margin-top:-20px;"></div>
	
	<!-- 外框阴影 -->
	<div class="center_shadow">
	  <div class="content">
	  
	  
	  
      <!-- 左侧栏 -->
      <div class="leftdiv">
        <!-- 导航栏 -->
        <div class="nav_menu">
			<a href="/index.do">资讯</a>
			<a href="/games.do">图鉴</a>
			<span>发售表</span>
			<a href="/laboratory.do">实验室</a>			
		</div>
        <!-- navigate -->
		
		<!-- 主显示区域 -->
		<div class="mainarea">
			<!-- 发售表 -->
			<div>
				<div id="retail_calendar" >
					<div>
						<span class="retail_datetitle" id="retail_date"></span>
						<span class="retail_datearrow_left" onclick="javascript:prevMonthRetail();"></span>
						<span class="retail_datearrow_right" onclick="javascript:nextMonthRetail();"></span>
					</div>
					<ul>
						<li class="inlineli retail_weekheader">星期日</li>					
						<li class="inlineli retail_weekheader">星期一</li>
						<li class="inlineli retail_weekheader">星期二</li>
						<li class="inlineli retail_weekheader">星期三</li>
						<li class="inlineli retail_weekheader">星期四</li>
						<li class="inlineli retail_weekheader">星期五</li>
						<li class="inlineli retail_weekheader">星期六</li>
					</ul>
					<div id="retail_sheet"></div>
					<div id="retail_wait">
						<img src="image/wait.gif" width="39" height="39" />
					</div>
					<div id="retail_error">
						<span>加载数据失败</span><a href="javascript:switchRetail();">重试</a>
					</div>
					
					<div id="retail_detail" class="retail_body" retailchild="true" onmouseout="javascript:hideRetailDetail(this,event);">						
						<big id="retail_detail_date" retailchild="true"></big>
						<div id="retail_detail_games" retailchild="true"></div>
					</div>
				</div>
			</div>
			<!-- mainarea_retail -->
		</div>
		<!-- mainarea -->
      </div>
	  <!-- left -->
	  
	  <%@ include file="index_right.jsp" %>
	  </div>
	  <!-- content -->
    </div>
	<!-- center_shadow -->
<div class="footer_shadow"></div>

<%@ include file="footer.jsp" %>

</div>
<!-- main -->

</div>

</body>
</html>
